package Leetcode第二期;

import java.util.Stack;

/**
 * @author : K k
 * @date : 22:53 2020/9/28
 */
public class 比较含退格的字符串_844 {
    public boolean backspaceCompare(String S, String T) {
        return build(S).equals(build(T));
    }

    public String build(String S) {
        Stack<Character> ans = new Stack();
        for (char c: S.toCharArray()) {
            if (c != '#')
                ans.push(c);
            else if (!ans.empty())
                ans.pop();
        }
        return String.valueOf(ans);
    }


    public static void main(String[] args) {
        比较含退格的字符串_844 x=new 比较含退格的字符串_844();
        System.out.println(x.backspaceCompare("a##c", "#a#c"));
    }
}
